package com.coocaa.internship.dao;

import com.coocaa.internship.dao.provider.CompanySqlProvider;
import com.coocaa.internship.pojo.Company;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: 公司dao层
 * @Author: zwh
 * @Date: 2019-07-25
 * @Time: 22:36
 */
@Mapper
@Component
public interface CompanyDao {
    String TABLE_NAME = "company";
    String SELECT_FIELDS = "company_id , company_name , company_logo , company_type , company_scale, company_email";
    String INSERT_FIELDS = "company_name , company_logo , company_type , company_scale , company_email";

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where company_id = #{companyId}"})
    Company selectCompanyById(@Param("companyId") Long companyId);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where company_name like '%${companyName}%'"})
    List<Company> selectCompaniesByName(@Param("companyName") String companyName);

    @Insert({"insert into ", TABLE_NAME, " (", INSERT_FIELDS, ") values (#{companyName} , #{companyLogo} , #{companyType} , #{companyScale} , #{companyEmail})"})
    @Options(useGeneratedKeys = true, keyColumn = "company_id", keyProperty = "companyId")
    Integer insertCompany(Company company);

    @Delete({"delete from ", TABLE_NAME, " where company_id = #{companyId}"})
    Integer deleteCompanyById(@Param("companyId") Long companyId);

    @UpdateProvider(value = CompanySqlProvider.class, method = "updateCompanyById")
    Integer updateCompanyById(Company company);
}
